package com.ylh.user.service;

import com.alibaba.fastjson.JSON;
import com.ylh.user.bo.UserBO;
import com.ylh.user.dao.UserDao;
import com.ylh.user.entity.UserDO;
import com.ylh.user.vo.UserVO;
import org.apache.commons.beanutils.BeanUtils;
import org.dozer.Mapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

/**
 * @ClassName UserService
 * @Description
 * @Author yanglh
 * @Date 2020/2/23 21:58
 */
@Service
public class UserService {
    @Resource
    private UserDao userDao;
    @Resource
    private Mapper mapper;

    public UserBO getUser(String name, String password){
        UserBO userBO = null;
        UserDO userDO = userDao.getUser(name,password);
        if(userDO != null){
            userBO = new UserBO();
            mapper.map(userDO,userBO);
        }
        return  userBO;
    }

    public int saveUser(UserVO userVo) {
        // todo 幂等控制
        UserDO userDO = new UserDO();
        mapper.map(userVo,userDO);
        return userDao.saveUser(userDO);
    }

    public static void main(String[] args) throws Exception{
        Map<String,String> map = new HashMap();
        String na = map.getOrDefault(null,"nihao");
        System.out.println(na);
    }
}
